package net.techwatch.fsindex;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

public class KeyGenerator extends JdbcDaoSupport {

	private static long id = 0L;
	private final static String STMT = "select max(fs_element_id) from fs_element";

	public KeyGenerator() {
		// nothing to do
	}

	public void init() {
		id = (Long) getJdbcTemplate().queryForObject(STMT, new RowMapper() {

			public Object mapRow(ResultSet resultSet, int rowIndex)
					throws SQLException {
				return resultSet.getLong(1);
			}

		});
	}

	public long getNewId() {
		++id;
		long tmp = id;
		return tmp;
	}

}
